<#import "../common/layout.ftl" as layout/>
<#import "../common/dataTables.ftl" as dataTables/>
<#import "../common/modern-forms.ftl" as mform/>
<#import "../common/modal.ftl" as modal/>


<!DOCTYPE html>
<html>
<@layout.head title="资产维护管理">
    <@dataTables.head/>
    <@dataTables.buttons_head/>
    <@dataTables.select_head/>
    <@dataTables.fixedHeader_head/>
    <@mform.head/>
    <@select.head/>
<style>
    #fjBox, #gdBox {
        font-size: 16px;
        line-height: 24px;
    }

    #fjBox .row, #gdBox .row {
        border: 1px dotted #ccc;
        margin: 10px 0px;
        position: relative;
        padding: 0px 20px;
    }

    #fjBox .title, #gdBox .title {
        font-weight: 600;
        line-height: 50px;
    }

    .deleteRow {
        position: absolute;
        right: 20px;
        top: 10px;
        width: 100px;
        height: 30px;
        line-height: 30px;
        color: #fff;
        background-color: darkred;
        text-align: center;
        border-radius: 5px;
    }

    .showImagBox {
        position: relative;
    }

    .showImag {
        display: block;
        background-color: #efefef;
        margin: 3px;
        max-width: 100%;
        height: 150px;
        position: relative;
    }

    .showImagBox img {
        max-width: 100%;
        min-height: 100px;
    }

    .showImagBox img:before {
        content: "点击上传";
        position: absolute;
        top: 50%;
        left: 50%;
        -webkit-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
        border-left: 2px solid #d9d9d9;
        color: #ccc;
        width: 160px;
        font-size: 1.4em;
        line-height: 39.5px;
        text-align: center;
        background-color: transparent;
    }

    .showImagBox img:after {
        left: calc(50% - 80px);
        content: " ";
        position: absolute;
        top: 50%;
        -webkit-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
        background-color: #d9d9d9;
        width: 39.5px;
        height: 2px;
    }

    body, html {
        background: none;
    }

    .imgButton {
        width: 100%;
        height: 40px;
        text-align: center;
        display: flex;
    }

    .imgButton span {
        flex: 1;
        margin: 0px 30px;
        display: block;
        font-size: 16px;
        line-height: 40px;
        background-color: #0ACD74;
        color: #fff;
        padding: 0px 50px;
        border-radius: 20px;
    }
</style>
<script src="${request.contextPath}/assets/js/myImgTool.js?v=3653060703"></script>
</@layout.head>
<body>
<@layout.page>
<div class="main-box">
    <div class="content">

        <div id="searchGroup" class="btn-group" style="position:relative;z-index: 1">
            <div style="float: left" id="orgBox">

            </div>
            <div style="float: left">
                <select class='form-control' id='types1' placeholder='请选择一级分类'
                        style='width:150px; margin-left: 10px;float: left' onchange="typesChange()">
                    <option value='0'>请选择一级分类-0</option>
                    <#list eqRootClass as item>
                        <option value="${item.id?c}">${item.name}-${item.code}</option>
                    </#list>
                </select>
            </div>
            <div style="float: left" id='types2Box'>
            </div>
            <select class='form-control' id='brand'
                    style='width:200px;float:left;margin-right:3px'>
                <option value="0">选择品牌</option>
                <#list brand as item>
                    <option value="${item.code}">${item.name}</option>
                </#list>
            </select>
            <input id="name" name="name" placeholder='型号名称/编码/二维码' style="margin-left:3px; width: 230px"/>
            <select class='form-control' id='repairState'
                    style='width:200px;float:left;margin-right:3px'>
                <option value="0">选择状态</option>
                <#list state as item>
                    <option value="${item.code}">${item.name}</option>
                </#list>
            </select>
        </div>
        <div style="margin-top:10px;  position:relative;z-index: 1 ; width:1100px;">
            <div>
                <span>新增时间</span>
                <input id="startdate" name="startdate" style="width: 100px" placeholder='请选择开始日期'/>
                <span>至</span>
                <input id="enddate" name="enddate" style="width: 100px" placeholder='请选择结束日期'/>
                <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                        onclick="javascript:refreshData();">
                    <i class="fa fa-search"></i> 查询
                </button>


                <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                        onclick="javascript:workOrder();">
                    <i class="fa fa-plus"></i> 工单配发
                </button>
                <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                        onclick="javascript:printOrder();">
                    <i class="fa fa-print"></i> 工单打印
                </button>
                <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                        onclick="javascript:refreshEnclosure();">
                    <i class="fa fa-upload"></i> 附件管理
                </button>
                <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                        onclick="javascript:refreshEnclosure2();">
                    <i class="fa fa-upload"></i> 工单补充
                </button>


            </div>
            <!-- 按钮 -->
        </div>
        <div style="position: relative;top:-30px; z-index: 0">
            <@dataTables.commonTable id="mainTable" maxWidth="200%" width="120%"/>
        </div>

    </div>

    <!-- 弹出窗 -->

<#--//附件管理-->
    <@modal.editModal id="modal-detail3" buttonId="btndetailSave3"  buttonName="新增附件" width="1000px">
        <div id="fjBox">

        </div>
    </@modal.editModal>
<#--附件新增-->
    <@modal.editModal id="modal-detail4" buttonId="btndetailSave4" width="500px" height="300px">
        <@mform.container  id="editForm4" width="450px">
            <input id="id" name="id" type="hidden"/>
            <input id="dataType" name="dataType" type="hidden" value="111001"/>

            <@mform.input_textarea id='fileDescribe' name='fileDescribe' size=12 label='补充内容' placeholder='补充内容'/>

            <div class="showImagBox">
                <img src="" class="showImag" id="show">
            </div>
            <div style="display: none">
                <@mform.input_file id='Img' name='Img' size=4 label='上传资产图片' placeholder='上传资产图片' icon='fa-edit' />
            </div>

        </@mform.container>
    </@modal.editModal>

<#--//工单补充管理-->
    <@modal.editModal id="modal-detail5" buttonId="btndetailSave5"  buttonName="补充说明" width="1000px">
        <div id="gdBox">

        </div>
    </@modal.editModal>
<#--工单补充新增-->
    <@modal.editModal id="modal-detail6" buttonId="btndetailSave6" width="500px" height="300px">
        <@mform.container  id="editForm6" width="450px">
            <input id="id" name="id" type="hidden"/>
            <input id="dataType" name="dataType" type="hidden" value="111002"/>

            <@mform.input_textarea id='fileDescribe' name='fileDescribe' size=12 label='补充内容' placeholder='补充内容'/>

        </@mform.container>
    </@modal.editModal>
<#--工单派发-->
    <@modal.editModal id="modal-detail1" buttonId="btndetailSave1" width="1000px" height="100px">
        <@mform.container  id="editForm1" >
            <input id="id" name="id" type="hidden"/>
            <div style="position: absolute;top:0px; z-index: 2">
                <@mform.row>
                    <div id="orgEditBox" style="float: left">
                    </div>
                    <button id="btnAddTopMenu" type="button" class="btn btn-blue btn-sm" style="margin-left: 5px;"
                            onclick="javascript:refreshDataWork();">
                        <i class="fa fa-search"></i> 查询
                    </button>
                </@mform.row>
            </div>
            <div style="position: relative;top:-15px;">
                <@dataTables.commonTable id="mainTable1"/>
            </div>
        </@mform.container>
    </@modal.editModal>

<#--维修结果-->
    <@modal.editModal id="modal-detail3" buttonId="btndetailSave3" width="500px" height="100px">
        <@mform.container  id="editForm3" width="450px">
            <input id="id" name="id" type="hidden"/>
            <@mform.select2 id='maintenanceResult' name='maintenanceResult' label="维修结果"  size=12>
                <option value="">请选择补充方式</option>
                <#list result as item>
                    <option value="${item.code}">${item.name}</option>
                </#list>
            </@mform.select2>
            <@mform.select2 id='maintenanceWay' name='maintenanceWay' label="维修方式"  size=12>
                <option value="">请选择补充方式</option>
                <#list maintenanceWay as item>
                    <option value="${item.code}">${item.name}</option>
                </#list>
            </@mform.select2>
            <@mform.input_textarea id='maintenanceDescribe' name='maintenanceDescribe' size=12 label='维修描述' placeholder='维修描述' />
            <@mform.input_text id='maintenanceTime' name='maintenanceTime' size=12 label='维修结束时间' placeholder='维修结束时间' icon='fa-edit' />
        </@mform.container>
    </@modal.editModal>
</@layout.page>
<@layout.foot>
    <@dataTables.foot/>
    <@dataTables.buttons_foot/>
    <@dataTables.select_foot/>
    <@dataTables.fixedHeader_foot/>
    <@mform.foot/>

    <script src="${request.contextPath}/assets/js/jquery.serializejson.min.js?v=3653060703"></script>
    <script type="text/javascript">
        var orgInfo =${organizationName};
        var orgInfoInner =${organizationInnerName};
        var orgSelect = $("<select id='oneOrganization' style='width:500px;'><option value='0'>请选择机构</option></select>");
        $("#orgBox").append(orgSelect);
        var orgEditSelect = $("<select id='organization' name='organization' style='width:300px;'></select>");
        $("#orgEditBox").append(orgEditSelect);
        putOptions(orgSelect, "", orgInfo.list);
        putOptions(orgEditSelect, "", orgInfoInner.list);

        function putOptions(orgSelect, supername, list) {
            if (supername != "") supername = supername + "-";
            for (var i = 0; i < list.length; i++) {
                orgSelect.append("<option value=" + list[i].id + ">" + supername + list[i].name + "</option>")
                if (list[i].childrenOrg.length > 0) {
                    putOptions(orgSelect, supername + list[i].name, list[i].childrenOrg);
                }
            }
        }

        orgSelect.select2();
        orgEditSelect.select2();

        function getType() {
            var types1 = $("#types1").find("option:selected").text().split("-")[1];
            var types2 = $("#types2").val();
            if (types2 == null || types2 == 0)
                return types1;
            else return types2;
        }

        function typesChange() {
            $.ajax({
                type: 'POST',
                data: {
                    datas: JSON.stringify({
                        superId: $("#types1").val()
                    })
                },
                url: "${request.contextPath}/base/eqClass/queryList",
                success: function (data) {
                    var data = data.datas;
                    //成功之后
                    var box = $("#types2Box");
                    box.html("");
                    if (data.length > 0 && $("#types1").val() != 0) {
                        //动态加载下拉框
                        var select = $("<select class='form-control' id='types2')> <option value=0>选择二级分类</option> </select>");
                        for (var i = 0; i < data.length; i++) {
                            select.append("<option value='" + data[i].code + "'>" + data[i].name + "</option>");
                        }
                        box.append(select);
                        select.select2();
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });
        }

        var now = new Date();
        var begin = now.getFullYear() + "-" + (now.getMonth() + 1) + "-1";
        var endD;
        var nextMonth = now.getMonth() + 1;
        var nextMonthFirstDay = new Date(now.getFullYear(), nextMonth, 1);
        var oneDay = 1000 * 60 * 60 * 24;
        endD = new Date(nextMonthFirstDay - oneDay);
        var end = endD.getFullYear() + "-" + (endD.getMonth() + 1) + "-" + endD.getDate();
        //    if(now.getMonth()!=11)
        //        end= now.getFullYear() + "-" + (now.getMonth() + 2) + "-1";
        //    else
        //        end= (now.getFullYear()+1) + "-1-1";
        $("#uploadTime").datetimepicker({
            language: "zh-CN",
            startView: 2,
            minView: 2,
            format: "yyyy-mm-dd",
            autoclose: true,
            initialDate: new Date(),
            todayBtn: true
        });
        $("#startdate").datetimepicker({
            language: "zh-CN",
            startView: 2,
            minView: 2,
            format: "yyyy-mm-dd",
            autoclose: true,
            initialDate: new Date(),
            todayBtn: true
        });
        $("#startdate").val(begin);
        $("#enddate").datetimepicker({
            language: "zh-CN",
            startView: 2,
            minView: 2,
            format: "yyyy-mm-dd",
            autoclose: true,
            todayBtn: true
        });
        $("#enddate").val(end);
        $("#startdate1").datetimepicker({
            language: "zh-CN",
            startView: 2,
            minView: 2,
            format: "yyyy-mm-dd",
            autoclose: true,
            initialDate: new Date(),
            todayBtn: true
        });
        $("#startdate1").val(begin);
        $("#enddate1").datetimepicker({
            language: "zh-CN",
            startView: 2,
            minView: 2,
            format: "yyyy-mm-dd",
            autoclose: true,
            todayBtn: true
        });
        $("#enddate1").val(end);
        var state = {
            <#list repairState as item>
                "${item.code}": "${item.name}",
            </#list>}
        var questionType = {
            <#list question as item>
                "${item.code}": "${item.name}",
            </#list>}
        var columns = [
            {"sWidth": "40px", "title": "id", "data": "id"},
            {"sWidth": "100px", "title": "资产位置", "data": "organizationName"},
            //{"sWidth": "100px", "title": "资产类型", "data": "type"},
            //{"sWidth": "100px", "title": "品牌", "data": "brand"},
            {"sWidth": "100px", "title": "基本信息", "data": "model"},
            //{"sWidth": "120px", "title": "资产名称", "data": "name"},
            // {"sWidth": "300px", "title": "资产条形码", "data": "barCode"},
            //{"sWidth": "120px", "title": "二维码", "data": "QRcode"},
            {"sWidth": "150px", "title": "问题", "data": "questionTypeCode"},
            // {"sWidth": "120px", "title": "问题描述", "data": "questionDescribe"},
            //{"sWidth": "80px", "title": "状态", "data": "repairState"},
            {"sWidth": "150px", "title": "申请信息", "data": "maintainName"},
            //{"sWidth": "80px", "title": "维护人", "data": "maintainName"},
            {"sWidth": "150px", "title": "时间点", "data": "createTime"},
            //{"sWidth": "80px", "title": "派单时间", "data": "allocationTime"},
            {"sWidth": "150px", "title": "维修信息", "data": "repairTime"},
            //{"sWidth": "80px", "title": "维修时长", "data": "repairLong"},
            {"sWidth": "150px", "title": "其他", "data": "num"},
            //{"sWidth": "80px", "title": "维修结果", "data": "repairResult"},
            {"sWidth": "150px", "title": "评价/回访", "data": "visitTime"}
            //{"sWidth": "80px", "title": "回访结果", "data": "visitResult"}
        ]
        var mainTable = $('#mainTable').winningTable({
            columns: columns,
            pageLength: 5,
            fixedHeader: false,
            searching: true,
            ordering: false,
            "columnDefs": [{
                "targets": [0],
                "visible": false
            }],
            buttons: [

            ],
            "rowCallback": function (row, data, index) {
                $('td', row).eq(0).html(data.organizationName + "<br>" + data.usePosition);
                $('td', row).eq(1).html(data.name + "<br>条形码：" + data.barCode + "<br>二维码：" + data.QRcode);
                $('td', row).eq(2).html(questionType[data.questionTypeCode] + "：" + "<br>" + data.questionDescribe);
                $('td', row).eq(3).html("申请人：" + data.maintainName + "<br>状态：" + data.repairState + "<br>单号：" + data.flowCode);
                $('td', row).eq(4).html("申请：" + data.createTime + "<br> 派单：" + data.allocationTime + "<br>完成：" + data.repairTime);
                $('td', row).eq(5).html("维修人：" + data.repairName + "<br>维修结果：" + data.repairResult + "<br>维修时长：" + data.repairLong);
                $('td', row).eq(6).html("申请人电话：" + data.createTel + "<br>维修人电话：" + data.repairTel + "<br>附件数量：" + data.num);
                $('td', row).eq(7).html(data.visitTime + "：" + data.visitResult + "<br>" + data.visitDescribe);
                if (!$('#mainTable').parent().hasClass("myTableWrap"))
                    $('#mainTable').wrap("<div class='myTableWrap' style='width: 100%;overflow: auto;'></div>");
            }
        });


        //主表刷新
        function refreshData() {
            var data = {
                datas: JSON.stringify({
                    type: getType(),
                    brand: $("#brand").val(),
                    oneOrganization: $("#oneOrganization").val(),
                    name: $("#name").val(),
                    repairState: $("#repairState").val(),
                    b_createTime: $("#startdate").val(),
                    e_createTime: $("#enddate").val()
                })
            }
            mainTable.queryData(" ${request.contextPath}/busi/equipment/manage/queryList", data);
        }

        refreshData();


        //附件管理
        function enclosureManage(data) {
            $('#modal-detail3').find(".modal-title").text('附件管理');
            $('#modal-detail3').modal();
            $("#btndetailSave3").unbind();
            $("#btndetailSave3").click(enclosureAdd);
            $("#fjBox").html("");
            $.ajax({
                type: 'POST',
                data: {
                    datas: "111001"
                },
                url: " ${request.contextPath}/busi/equipment/manage/queryEnclosure/" + data.id,
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        $(data.datas).each(function (index, item) {
                            var row = $("<div class='row'><div class='title'>" + item.createTime + "：" + item.uploadName + "</div><div class='deleteRow'>删除</div><div>" + item.fileDescribe + "</div><img src='" + item.fileAddress + "'/></div>")
                            $("#fjBox").append(row);
                            row.find(".deleteRow").on("click", function () {
                                swal({
                                    title: "确定删除",
                                    text: "是否确定删除此数据",
                                    type: "warning",
                                    showCancelButton: true,
                                    confirmButtonColor: "#DD6B55",
                                    confirmButtonText: "是的,确定",
                                    cancelButtonText: "取消"
                                }).then(function (result) {
                                    if (!result.value)
                                        return;
                                    var requestData = {
                                        id: item.id
                                    };
                                    var params = {datas: JSON.stringify(requestData)};
                                    $.ajax({
                                        type: 'POST',
                                        data: params,
                                        url: ' ${request.contextPath}/busi/equipment/manage/enclosureDelete',
                                        success: function (data) {
                                            row.remove();
                                        },
                                        error: function (xhr, type) {
                                            swal("错误", "系统发生内部错误!请稍后再试!", "error");
                                        }
                                    });
                                });
                            })
                        })

                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });

        <#--mainTable3.queryData(" ${request.contextPath}/busi/equipment/manage/queryEnclosure/" + data.id);-->
        }

        $("#show").on("click", function () {
            $("#Img").trigger("click")
        })
        $("#Img").on("change", function () {
            //获取文件  
            var file = $("#Img")[0].files;
            imgZip(file, $("#show"), 800, 800);
        })

        function enclosureAdd() {
            $('#modal-detail4').find(".modal-title").text('附件新增');
            clearForm($('#modal-detail4'));
            $("#show").attr("src", "");
            $("#btndetailSave4").unbind();
            $("#btndetailSave4").click(saveEnclosure);
            $('#modal-detail4').modal();
        }

        function enclosureAdd2() {
            $('#modal-detail6').find(".modal-title").text('工单补充新增');
            clearForm($('#modal-detail6'));
            $("#btndetailSave6").unbind();
            $("#btndetailSave6").click(saveEnclosure2);
            $('#modal-detail6').modal();
        }

        //附加查询
        function refreshEnclosure(data) {
            if (data == null) {
                var datas = mainTable.getSelectedDatas();
                if (datas == null || datas.length == 0 || datas.length > 1) {
                    swal("错误", "请选择一行数据", "error");
                    return;
                }
                data = datas[0];
            }
            selectMainRow = data;
            enclosureManage(data);
        }


        //新增附件
        function saveEnclosure() {
            swal({
                title: "确定保存",
                text: "是否确定保存此数据",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的,确定",
                cancelButtonText: "取消"
            }).then(function (result) {
                if (!result.value)
                    return;
                var requestData = $("#editForm4 form").serializeJSON();
                if (requestData.fileDescribe == "") {
                    swal("错误", "请输入补充说明内容", "error");
                    return;
                }
                requestData.dataType = '111001';
                requestData.repairApplyId = selectMainRow.id;
                var scoreImg = $("#show").attr("src");
                if (scoreImg.startsWith("data:image")) {
                    requestData.filePic = scoreImg;
                } else {
                    requestData.filePic = "";
                }
                var params = {datas: JSON.stringify(requestData)};
                $.ajax({
                    type: 'POST',
                    data: params,
                    url: ' ${request.contextPath}/busi/equipment/manage/enclosureSave',
                    success: function (data) {
                        //成功之后
                        if (data.success) {
                            swal({
                                title: "成功",
                                text: "操作成功!",
                                type: "success",
                                showCancelButton: false,
                                confirmButtonText: "确定"
                            }).then(function (result) {
                                $("#modal-detail4").modal('hide');
                                refreshEnclosure(selectMainRow);
                                refreshData();
                            });
                        } else {
                            swal("错误", data.errorMsg, "error");
                        }
                    },
                    error: function (xhr, type) {
                        swal("错误", "系统发生内部错误!请稍后再试!", "error");
                    }
                });
            });
        }

        //补充工单查询
        function refreshEnclosure2(data) {
            if (data == null) {
                var datas = mainTable.getSelectedDatas();
                if (datas == null || datas.length == 0 || datas.length > 1) {
                    swal("错误", "请选择一行数据", "error");
                    return;
                }
                data = datas[0];
            }
            selectMainRow = data;
            enclosureManage2(data);
        }

        //补充工单管理
        function enclosureManage2(data) {
            $('#modal-detail5').find(".modal-title").text('工单补充管理');
            $('#modal-detail5').modal();
            $("#btndetailSave5").unbind();
            $("#btndetailSave5").click(enclosureAdd2);
            $("#gdBox").html("");
            $.ajax({
                type: 'POST',
                data: {
                    datas: "111002"
                },
                url: " ${request.contextPath}/busi/equipment/manage/queryEnclosure/" + data.id,
                success: function (data) {
                    //成功之后
                    if (data.success) {
                        $(data.datas).each(function (index, item) {
                            var row = $("<div class='row'><div class='title'>" + item.createTime + "：" + item.uploadName + "</div><div class='deleteRow'>删除</div><div>" + item.fileDescribe + "</div><img src='" + item.fileAddress + "'/></div>")
                            $("#gdBox").append(row);
                            row.find(".deleteRow").on("click", function () {
                                swal({
                                    title: "确定删除",
                                    text: "是否确定删除此数据",
                                    type: "warning",
                                    showCancelButton: true,
                                    confirmButtonColor: "#DD6B55",
                                    confirmButtonText: "是的,确定",
                                    cancelButtonText: "取消"
                                }).then(function (result) {
                                    if (!result.value)
                                        return;
                                    var requestData = {
                                        id: item.id
                                    };
                                    var params = {datas: JSON.stringify(requestData)};
                                    $.ajax({
                                        type: 'POST',
                                        data: params,
                                        url: ' ${request.contextPath}/busi/equipment/manage/enclosureDelete',
                                        success: function (data) {
                                            row.remove();
                                        },
                                        error: function (xhr, type) {
                                            swal("错误", "系统发生内部错误!请稍后再试!", "error");
                                        }
                                    });
                                });
                            })
                        })

                    } else {
                        swal("错误", data.errorMsg, "error");
                    }
                },
                error: function (xhr, type) {
                    swal("错误", "系统发生内部错误!请稍后再试!", "error");
                }
            });

        <#--mainTable3.queryData(" ${request.contextPath}/busi/equipment/manage/queryEnclosure/" + data.id);-->
        }

        var selectMainRow = null;

        //新增工单补充
        function saveEnclosure2() {
            swal({
                title: "确定保存",
                text: "是否确定保存此数据",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的,确定",
                cancelButtonText: "取消"
            }).then(function (result) {
                if (!result.value)
                    return;
                var requestData = $("#editForm6 form").serializeJSON();
                if (requestData.fileDescribe == "") {
                    swal("错误", "请输入补充说明内容", "error");
                    return;
                }
                requestData.dataType = '111002';
                requestData.repairApplyId = selectMainRow.id;
                requestData.filePic = "";
                var params = {datas: JSON.stringify(requestData)};
                $.ajax({
                    type: 'POST',
                    data: params,
                    url: ' ${request.contextPath}/busi/equipment/manage/enclosureSave',
                    success: function (data) {
                        //成功之后
                        if (data.success) {
                            swal({
                                title: "成功",
                                text: "操作成功!",
                                type: "success",
                                showCancelButton: false,
                                confirmButtonText: "确定"
                            }).then(function (result) {
                                $("#modal-detail6").modal('hide');
                                refreshEnclosure2(selectMainRow);
                                refreshData();
                            });
                        } else {
                            swal("错误", data.errorMsg, "error");
                        }
                    },
                    error: function (xhr, type) {
                        swal("错误", "系统发生内部错误!请稍后再试!", "error");
                    }
                });
            });
        }

        //工单配发
        var columns1 = [
            {"sWidth": "100px", "title": "机构名称", "data": "organizationName"},
            {"sWidth": "100px", "title": "姓名", "data": "staffName"},
            {"sWidth": "100px", "title": "未完成工单数", "data": "num"},
            {"sWidth": "100px", "title": "未完成派单开始时间", "data": "minTime"},
            {"sWidth": "120px", "title": "未完成派单结束时间", "data": "maxTime"}
        ]
        var mainTable1 = $('#mainTable1').winningTable({
            columns: columns1,
            pageLength: 10,
            fixedHeader: false,
            searching: true,
            ordering: true,
            buttons: [

            ],
            "rowCallback": function (row, data, index) {
                $('td', row).eq(11).html(state[data.state]);
            }
        });

        //工单配发
        function workOrder() {
            var datas = mainTable.getSelectedDatas();
            if (datas == null || datas.length == 0 || datas.length > 1) {
                swal("错误", "请选择一行数据", "error");
                return;
            }
            if (datas[0].state != "201203"&&datas[0].state != "201301"&&datas[0].state != "201302"&&datas[0].state != "201502") {
                swal("错误", "维修单状态不允许现在配发", "error");
                return;
            }
            if (datas[0].reSrState == "209001") {
                swal("错误", "已经派发，等待维修工受理中", "error");
                return;
            } else if (datas[0].reSrState == "209002") {
                swal("错误", "已经派发，维修工已受理", "error");
                return;
            }
            $('#modal-detail1').find(".modal-title").text('工单配发');
            refreshDataWork();
            $("#btndetailSave1").unbind();
            $("#btndetailSave1").click(workOrderAllotment);
            $('#modal-detail1').modal();
        }

        //工单打印
        function printOrder() {
            var datas = mainTable.getSelectedDatas();
            if (datas == null || datas.length == 0 || datas.length > 1) {
                swal("错误", "请选择一行数据", "error");
                return;
            }
            window.open("${request.contextPath}/busi/equipment/Handle/print/" + datas[0].id);
        }

        function refreshDataWork() {
            var param = {
                datas: JSON.stringify({
                    organization: $("#organization").val(),
                })
            }
            mainTable1.queryData(" ${request.contextPath}/busi/equipment/Handle/queryWork", param);
        }

        //工单配发
        function workOrderAllotment() {
            var datas = mainTable.getSelectedDatas();
            if (datas == null || datas.length == 0 || datas.length > 1) {
                swal("错误", "请选择一行数据", "error");
                return;
            }
            var datas1 = mainTable1.getSelectedDatas();
            if (datas1 == null || datas1.length == 0 || datas1.length > 1) {
                swal("错误", "请选择一行数据", "error");
                return;
            }
            swal({
                title: "确定保存",
                text: "是否确定保存此数据",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的,确定",
                cancelButtonText: "取消"
            }).then(function (result) {
                if (!result.value)
                    return;
                var data = datas[0];
                var data1 = datas1[0];
                var requestData = {
                    repairApplyId: data.id,
                    equipmentId: data.equipmentId,
                    mFlowCode: data.flowCode,
                    eCode: data.QRcode,
                    telephone: data.createTel,
                    name: data.maintainName,
                    eType: data.oneCode,
                    toStaffId: data1.id
                };
                var params = {datas: JSON.stringify(requestData)};
                $.ajax({
                    type: 'POST',
                    data: params,
                    url: ' ${request.contextPath}/busi/equipment/Handle/saveWorkOrder',
                    success: function (data) {
                        //成功之后
                        if (data.success) {
                            swal({
                                title: "成功",
                                text: "操作成功!",
                                type: "success",
                                showCancelButton: false,
                                confirmButtonText: "确定"
                            }).then(function (result) {
                                $("#modal-detail1").modal('hide');
                                refreshData();
                            });
                        } else {
                            swal("错误", data.errorMsg, "error");
                        }
                    },
                    error: function (xhr, type) {
                        swal("错误", "系统发生内部错误!请稍后再试!", "error");
                    }
                });
            });
        }

    </script>
</@layout.foot>
</body>
</html>